<?php

namespace app\models;

class DemoModel extends BaseModel
{
    public function login($data)
    {
        return array('userData' => 'userData');

        /*
        // 查询一条
        $sql = 'SELECT * FROM e_user WHERE id = :id LIMIT 1';
        $res = parent::$mysql->createCommand($sql);
        $res->bindValue(':id', 1);
        $data = $res->queryOne();
        return $data;

        // 查询多条
        $sql = 'SELECT * FROM e_user WHERE age = :age LIMIT 100';
        $res = parent::$mysql->createCommand($sql);
        $res->bindValue(':age', 30);
        $data = $res->queryAll();
        return $data;

        // 执行
        $sql = 'INSERT INTO e_user(advId,balance)VALUES(:advId,:balance)';
        $res = parent::$mysql->createCommand($sql);
        $res->bindValue(':advId', $data['advId']);
        $res->bindValue(':balance', $data['balance']);
        $res = $res->execute();
        return $res;

        // 事务
        $transaction = parent::$mysql->beginTransaction();
        $i = 0;
        try {

            $sql = array();
            $sql['e_user'] = 'INSERT INTO e_user(advId,balance)VALUES(:advId,:balance)';
            $res = parent::$mysql->createCommand($sql);
            $res->bindValue(':advId', $data['advId']);
            $res->bindValue(':balance', $data['balance']);
            $res = $res->execute();
            if (!$res) {
                // 回滚
                $transaction->rollBack();
            }

            $sql['advspend'] = 'UPDATE advspend SET lastTime = :lastTime WHERE advId = :advId';
            $res = parent::$mysql->createCommand($sql['advspend']);
            $res->bindValue(':lastTime', $data['lastTime']);
            $res->bindValue(':advId', $data['advId']);
            $res = $res->execute();
            if ($res === false) {
                // 回滚
                $transaction->rollBack();
            }

            // 提交事务
            $transaction->commit();
            return true;

        } catch (\Exception $e) {
            $transaction->rollBack();
            return false;
        } catch (\Throwable $e) {
            $transaction->rollBack();
            return false;
        }

        */
    }
}